package demo.demo;

import java.util.Random;

import custom.java.util.Objects;

public class Person {
	private String mName;
	private int age;

	public Person(String Name, int age){
		Objects.requireNonNull(Name);
		this.mName = Name;
		this.age = age;
	}

	@Override
	public int hashCode() {
		Objects.hash(mName,age);
		return super.hashCode();
	}
	
	public static Person generate() {
		int nameLen = new Random().nextInt(5) + 5;
		int age = new Random().nextInt(30) + 20;
		 Person person = new Person(genName(nameLen),age);
		 return person;
		
	}

	private static String genName(int size) {
		int beg = 0x61;
		int end = 0x7a;
		int delta = end-beg;
		
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < size; i++) {		
			char[] chars = Character.toChars(beg + new Random().nextInt(delta));
			sb.append(chars);
		}
		sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
		return sb.toString();
	}

	@Override
	public String toString() {
		return String.format("Person: %-10s %d", mName, age);
	}
}
